import random

list_name = [["糖炒栗子", 15],
             ["盐炒栗子", 29],
             ["醋溜栗子", 40],
             ['栗子火锅', 200],
             ["凉拌栗子", 50],
             ["栗子汁", 10],
             ["栗子炸鸡", 40],
             ["栗子可乐", 15],
             ["冰糖栗子", 25]
             ]

list_name1 = [["糖炒栗子八折", 10.5],
              ["盐炒栗子八折", 20.3],
              ["醋溜栗子九折", 36],
              ['栗子火锅九折', 180],
              ["凉拌栗子七折", 35],
              ["栗子汁九折", 9],
              ["栗子炸鸡九折", 36],
              ["栗子可乐九折", 13.5],
              ["冰糖栗子九折", 22.5]
              ]
list_name2 = [["糖炒栗子八折", 12],
              ["盐炒栗子八折", 20],
              ["醋溜栗子九折", 28],
              ['栗子火锅九折', 140],
              ["凉拌栗子七折", 35],
              ["栗子汁九折", 7],
              ["栗子炸鸡九折", 28],
              ["栗子可乐九折", 10.5],
              ["冰糖栗子九折", 17.5]
              ]

# 钱包
money = 700
# 购物车
mycar = []

for i in enumerate(list_name):
    print(i)

name5 = random.randint(1, 4)  # 随机1是优惠价，2双十一， 3是满200减20
name = random.randint(0, 9)  # 随机商品的优惠卷
num_zhang = 0
if name5 == 1:
    name = random.randint(0, 9)  # 随机商品的优惠卷
    num_zhang = random.randint(1, 4)  # 优惠价的张数
    print("恭喜你获得了:", list_name1[name][0], "优惠价", num_zhang, "张")
elif name5 == 2:
    print("参见双十一全场商品七折优惠")
else:
    print("获得满200减20优惠")
while True:
    shop = input("请输入商品编号:")
    if shop.isdigit():  # 判断字符串内是否由数字组成   返回bool
        shop = int(shop)  # 转换类型
        if 0 <= shop <= 8:
            if -1 < name < 9 and list_name[name][0] == list_name[shop][0] and num_zhang > 0:
                # if num_zhang > 0:
                num_zhang = num_zhang - 1
                print("还剩下", num_zhang, "优惠卷")
                if money >= list_name1[shop][1]:  # 判断钱够不够
                    # list_name[shop][1] = list_name1[name][1]
                    mycar.append(list_name1[shop])  # 加购物车
                    money = money - list_name1[shop][1]  # 减去金额
                    print("花了", list_name1[shop][1])
                    print("购买成功已经加入购物车,剩余金额为", money)
                else:
                    print("您的余额不足")
            elif 0 <= shop <= 8:
                if money >= list_name[shop][1]:  # 判断钱够不够
                    mycar.append(list_name[shop])  # 加购物车
                    money = money - list_name[shop][1]  # 减去金额
                    print("花了", list_name[shop][1])
                    print("购买成功已经加入购物车,剩余金额为", money)
                else:
                    print("您的余额不足")
            elif name5 == 2:
                if money >= list_name2[shop][1]:  # 判断钱够不够
                    mycar.append(list_name2[shop])  # 加购物车
                    money = money - list_name2[shop][1]  # 减去金额
                    print("花了", list_name2[shop][1])
                    print("购买成功已经加入购物车,剩余金额为", money)
                else:
                    print("您的余额不足")
        else:
            print("没有此商品，输入有误")

    elif shop == "q" or shop == "Q":
        if money <= 500 and name5 == 3: # 进行满200减20
            print("欢迎下次光临以下是您购买的详细内容")
            for i in enumerate(mycar):
                print(i)
            money = money + 20 # 满足上面的要求执行这个步骤
            print("剩余金额为:", money)
            break
        else:
            print("欢迎下次光临以下是您购买的详细内容")
            for i in enumerate(mycar):
                print(i)
            print("剩余金额为:", money)
            break

    else:
        print("输入的格式有误请重新输入")
